//createRouter:创建router实例路由
//createWebHistory:路由方式
import { createRouter, createWebHistory } from 'vue-router'
import Login from '@/views/Login/index.vue'
import Layout from '@/views/Layout/index.vue'
import Category from '@/views/Category/index.vue'
import Home from '@/views/Home/index.vue'
import subCategory from '@/views/subCategory/index.vue'
import Detail from '@/views/Detail/index.vue'
import cartList from '@/views/cartList/index.vue'
// import pay from '@/views/pay/index.vue'
// import payBack from '@/views/pay/payBack.vue'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',  //表示首次打开的路由
      name: 'Layout',
      component: Layout,
      //定义别名
      // redirect: '/home',-----重定向
      children: [{
        path: '',
        name: 'home',  //默认二级路由
        component: Home
      },
      {
        //组件参数占位
        path: 'category/:id',//二级路由不需要写/
        name: 'category',
        component: Category
      },
      {
        //组件参数占位
        path: 'category/sub/:id',//二级路由不需要写/
        name: 'subCategory',
        component: subCategory
      },
      {
        //组件参数占位
        path: 'detail/:id',//二级路由不需要写/
        name: 'detail',
        component: Detail
      },  
      {
        //组件参数占位
        path: 'cartList',//二级路由不需要写/
        name: 'cartList',
        component: cartList
      },
      {
        path: 'checkOut',//二级路由不需要写/
        name: 'checkOut',
        component: () => import("@/views/checkOut/index.vue")
      },
      {
        path: 'pay',//二级路由不需要写/
        name: 'pay',
        component: () => import("@/views/pay/index.vue")
      },
      {
        path: 'paycallback',
        name: 'paycallback',
        component: () => import("@/views/pay/payBack.vue")
      },
      {
        path: 'member',
        name: 'member',
        component: () => import("@/views/Member/index.vue"),
        //重定向到个人中心页面（即一打开便是默认个人中心页面）
        redirect: 'member/user',
        children: [
          {
            path: 'user',
            name: 'userInfo',
            component: () => import('@/views/Member/components/userInfo.vue')
          },
          {
            path: 'order',
            name: 'userOrder',
            component: () => import('@/views/Member/components/userOrder.vue')
          }
        ]
      }
      ]
    },
    {
      path: '/login',
      name: 'login',
      component: Login
    }
  ],
  //路由行为定制
  scrollBehavior() {
    return {
      top: 0
    }
  }
})

export default router
